package com.example.day20_zhongji.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.example.day20_zhongji.R;

import java.util.List;

public class Listadapter extends BaseExpandableListAdapter {
    private List<String> group;
    private List<List<String>> children;
    private Context context;

    public Listadapter(List<String> group, List<List<String>> children, Context context) {
        this.group = group;
        this.children = children;
        this.context = context;
    }

    @Override
    public int getGroupCount() {
        return group.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return children.get(i).size();
    }

    @Override
    public Object getGroup(int i) {
        return group.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return children.get(i).get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        if (view==null){
             view= LayoutInflater.from(context).inflate(R.layout.group, null);
        }
        TextView viewById = view.findViewById(R.id.tile_group);
        viewById.setText(group.get(i));
        TextView li = view.findViewById(R.id.li_group);
        li.setText("4/44");
        return view;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        if (view==null){
            view=LayoutInflater.from(context).inflate(R.layout.child,null);
        }
        TextView child = view.findViewById(R.id.child);
        child.setText(children.get(i).get(i1));
        return view;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return false;
    }
}
